package cn.monkey.controller;

import cn.monkey.pojo.Menu;
import cn.monkey.service.MenuService;
import cn.monkey.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class MenuController {
    @Autowired
    MenuService menuService;

    //查询单个权限
    @GetMapping("/system/menuManagement/get/{mid}")
    public ResultVo selectMenu(@PathVariable Long mid){
        Menu menu = menuService.getById(mid);
        List<Menu> menuAll = menuService.getMenuAll();
        return ResultVo.success(menu);
    }

    //权限管理，显示全部权限
    @GetMapping("/system/menuManagement/getAll")
    public ResultVo selectMenuAll(){
        List<Menu> menuAll = menuService.getMenuAll();
        return ResultVo.success(menuAll);
    }


    @PostMapping("/system/menuManagement/insert")
    public ResultVo menuInsert(@RequestBody Menu menu){
        return menuService.save(menu) ? ResultVo.success("新增菜单成功!",null):ResultVo.error("新增菜单失败!");
    }

    @PostMapping("/system/menuManagement/update")
    public ResultVo menuUpdate(@RequestBody Menu menu){
        return menuService.updateById(menu) ? ResultVo.success("修改菜单成功!",null):ResultVo.error("修改菜单失败!");
    }

    @PostMapping("/system/menuManagement/delete")
    public ResultVo menuDelete(@RequestBody Menu menu){
        return menuService.updateById(menu) ? ResultVo.success("修改菜单成功!",null):ResultVo.error("修改菜单失败!");
    }
}
